import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/views/layout'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        label: '工作台',
        component: () => import('@/views/home')
      },
      {
        path: '/stockManage',
        name: 'stockManage',
        label: '仓库管理',
        component: () => import('@/views/baseInfo/storeManage')
      },
      {
        path: '/detail',
        name: 'detail',
        component: () => import('@/views/baseInfo/detail')
      },
      {
        path: '/reservoirManage',
        name: 'reservoirManage',
        component: () => import('@/views/baseInfo/reservoirManage')
      },
      {
        path: '/detail1',
        name: 'detail1',
        component: () => import('@/views/baseInfo/detail1')
      },
      {
        path: '/detail2',
        name: 'detail2',
        component: () => import('@/views/baseInfo/detail2')
      },
      {
        path: '/detail3',
        name: 'detail3',
        component: () => import('@/views/baseInfo/detail3')
      },
      {
        path: '/storageManage',
        name: 'storageManage',
        component: () => import('@/views/baseInfo/storageManage')
      },
      {
        path: '/storageView',
        name: 'storageView',
        component: () => import('@/views/baseInfo/storageView')
      },
      {
        path: '/shoppingManage',
        name: 'shoppingManage',
        component: () => import('@/views/baseInfo/shoppingManage')
      },
      {
        path: '/shoppingType',
        name: 'shoppingType',
        component: () => import('@/views/baseInfo/shoppingType')
      },

      // 货主管理路由
      {
        path: '/ownerManage',
        name: 'ownerManage',
        component: () => import('@/views/business/ownerManage')
      },
      {
        path: '/addOwner',
        name: 'addOwner',
        component: () => import('@/views/business/addOwner')
      },
      {
        path: '/commonCarrierManage',
        name: 'commonCarrierManage',
        component: () => import('@/views/business/commonCarrierManage')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login')
  }
]

const router = new VueRouter({
  routes
})

// 获取原型对象push函数
const originalPush = VueRouter.prototype.push

// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace

// 修改原型对象中的push函数
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace (location) {
  return originalReplace.call(this, location).catch(err => err)
}

export default router
